<?
	header("Content-Type:text/plain\n\n");
  require_once( "../base/ccdsBackendPlugin.inc.php" );
  require_once( "../base/ccdsBackendUserPlugin.inc.php" );
  require_once( "../base/ccdsConfigParser.inc.php" );
  require_once( "../base/ccdsConfig.inc.php" );
  require_once( "../base/ccdSQL.inc.php" );
  require_once( "../base/ccdsXajax.inc.php" );

  require_once( "../base/ccdsModuleManager.inc.php" );
  require_once( "../base/ccdsTools.inc.php" );

  require_once( "../base/ccdsObjectConfig.inc.php" );
  require_once( "../base/ccdsObject.inc.php" );
  require_once( "../base/ccdsObjectHandler.inc.php" );
  require_once( "../base/ccdsForms.inc.php" );


/*
		function getNaviTree($root_id,$lastpages) {
			$results = array();
			$query = "SELECT * FROM obj_index LEFT OUTER JOIN obj_names ON (obj_name_key_obj_id = obj_id AND obj_name_key_lang_id='".$_SESSION['CMS']['user_lang_id']."') WHERE obj_parent_obj_id = '".$root_id."'  ORDER BY obj_position";
			$res = mysql_query($query);
			while ($row = mysql_fetch_array($res)) {
					if ($row['obj_name_name'] == "") $row['obj_name_name'] = ObjectHandler::getAlternativeObjName($row['obj_id']);
				
					$results[]=array("name" => $lastpages.$row['obj_name_name'],"value" => $row['obj_id'],"url" => "/".$row['obj_id']."/".rewrite_name($row['obj_name_name']));
					$tmp_array=getNaviTree($row['obj_id'],$lastpages.$row['obj_name_name'].">");
					$results=array_merge($results,$tmp_array);
			}		
			return $results;
		}

*/

	function getNaviTree($lang,$root_id,$lastpages,$lastobj="") {
		global $seperator;
		$query = "SELECT * FROM obj_index LEFT JOIN obj_names 
		
					ON obj_name_key_obj_id = obj_id 
					LEFT JOIN languages ON
					(obj_name_key_lang_id = lang_id)
					
					WHERE obj_parent_obj_id = '".$root_id."' AND obj_deleted=0 and obj_is_navi=1 AND lang_id='".$lang."'
					ORDER BY obj_position
					
					
					";
		$res = mysql_query($query);
		while ($row = mysql_fetch_array($res)) {
			if ($row['obj_is_navi'] == "1") {
				print $seperator."[\"".$row['lang_code']."/".$lastpages.$row['obj_name_name']."\", \"/".$row['lang_code']."/".$lastobj.$row['obj_name_serialized']."\"]\n";
				$seperator=",";
				getNaviTree($lang,$row['obj_id'],$lastpages.$row['obj_name_name'].">",$lastobj.$row['obj_name_serialized']."/");
			
			}
		}		
	}
	
	
	print "var tinyMCELinkList = new Array(\n";	
	$seperator="";
	$query = "SELECT * FROM obj_index WHERE obj_parent_obj_id='0'";
	$res = mysql_query($query);
	$project = mysql_fetch_assoc($res);


	$query = "SELECT * FROM languages";
	$resL = mysql_query($query);
	while ($lang = mysql_fetch_assoc($resL)) {

			$temp = getNaviTree($lang['lang_id'],$project['obj_id'],"");
	
//		$query = "SELECT * FROM obj_index WHERE obj_parent_obj_id='".$project['obj_id']."' ORDER BY obj_position";
//		$res = mysql_query($query);
//		$pages = array();
//		while ($row = mysql_fetch_assoc($res)) {
//			$temp = getNaviTree($lang['lang_id'],$row['obj_id'],"");
//			//$pages = array_merge($pages,$temp);		
//		}

	}
	
	
/*
	["Moxiecode", "http://www.moxiecode.com"],
	["Freshmeat", "http://www.freshmeat.com"],
	["Sourceforge", "http://www.sourceforge.com"]
*/
	print ");";	

	// Name, URL


?>